﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BDSim
{
    public class MasterStationDataProvider: BDSimDataProvider
    {
        private MasterStation _Parent;

        public MasterStation Parent
        {
            get { return _Parent; }
            set { _Parent = value; }
        }

        #region 命令定义
        public override void DefineCommand()
        {
            MenuCommand mcdEphemerisErrorConfig = new MenuCommand() { Header = "星历误差配置"};
            mcdEphemerisErrorConfig.DefineExcuteCommand(mcdEphemerisErrorConfig_Execute, mcdEphemerisErrorConfig_CanExecute); 
            MenuCommandList.Add(mcdEphemerisErrorConfig);

            MenuCommand mcdEphemericReport = new MenuCommand() { Header = "星历数据报告" };
            mcdEphemericReport.DefineExcuteCommand(mcdEphemericReport_Execute, mcdEphemericReport_CanExecute);
            MenuCommandList.Add(mcdEphemericReport);

            MenuCommand ClockReport = new MenuCommand() { Header = "生成报告" };
            ClockReport.DefineExcuteCommand(ClockReport_Execute, ClockReport_CanExecute);
            MenuCommand ClockFigure = new MenuCommand() { Header = "生成图表" };
            ClockFigure.DefineExcuteCommand(ClockFigure_Execute, ClockFigure_CanExecute);
            MenuCommand ClockDataExport = new MenuCommand() { Header = "钟差数据" };
            ClockDataExport.SubMenuCommandList.Add(ClockReport);
            ClockDataExport.SubMenuCommandList.Add(ClockFigure);
            MenuCommandList.Add(ClockDataExport);

            MenuCommand mcdDelete = new MenuCommand() { Header = "删除" };
            mcdDelete.DefineExcuteCommand(mcdDelete_Execute, mcdDelete_CanExecute);
            MenuCommandList.Add(mcdDelete);
        }
        #endregion

        #region 命令执行方法
 
        #region 删除命令执行方法
        /// <summary>
        /// 删除接收机功能命令执行方法
        /// </summary>
        /// <param name="param"></param>
        void mcdDelete_Execute(object param)
        {
            Parent.Parent.StationList.Remove(Parent);
        }
        /// <summary>
        /// 删除接收机功能命令可执行控制
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        bool mcdDelete_CanExecute(object param)
        {
            bool flag = false;
            if (BDSimObject.GlobalStatus == ESimStatus.UnInited || BDSimObject.GlobalStatus == ESimStatus.End)
            {
                flag = true;
            }
            return flag;
        }

        #endregion

        #region 卫星星历报告执行方法
        /// <summary>
        /// 卫星星历报告功能命令执行方法
        /// </summary>
        /// <param name="param"></param>
        void mcdEphemericReport_Execute(object param)
        {
            DataReportView dataPreview = new DataReportView();
            dataPreview.InitEphemerisData(this.Parent.SatEph16Dic);
            MainDispatcher.DlgAddLayoutDocument(dataPreview, this.Parent.Name + "_星历数据");
        }
        /// <summary>
        /// 卫星星历报告功能命令可执行控制
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        bool mcdEphemericReport_CanExecute(object param)
        {
            bool flag = false;
            if (Scenario._IsFitEphemeris && (BDSimObject.GlobalStatus == ESimStatus.Inited || BDSimObject.GlobalStatus == ESimStatus.Pause))
            {
                flag = true;
            }
            return flag;
        }

        #endregion

        #region 钟差报告执行方法
        /// <summary>
        /// XXX 功能命令执行方法
        /// </summary>
        /// <param name="param"></param>
        void ClockReport_Execute(object param)
        {
            DataReportView dataPreview = new DataReportView();
            List<ClkSimData> InterSatClkErrList = new List<ClkSimData>();
            InterSatClkErrList = Parent.GenerateStepCLKErr();
            dataPreview.InitClkData(InterSatClkErrList, Parent.Name);
            MainDispatcher.DlgAddLayoutDocument(dataPreview, Parent.Name);
        }
        /// <summary>
        /// XXX功能命令可执行控制
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        bool ClockReport_CanExecute(object param)
        {
            bool flag = false;
            if (BDSimObject.GlobalStatus == ESimStatus.Inited || BDSimObject.GlobalStatus == ESimStatus.Pause)
            {
                flag = true;
            }
            return flag;
        }
        #endregion

        #region 钟差绘图执行方法
        /// <summary>
        /// XXX 功能命令执行方法
        /// </summary>
        /// <param name="param"></param>
        void ClockFigure_Execute(object param)
        {
            DataFigureView clkFigureView = new DataFigureView();
            List<ClkSimData> InterSatClkErrList = new List<ClkSimData>();
            InterSatClkErrList = Parent.GenerateStepCLKErr();
            clkFigureView.InitClkCharts(Parent.Name, InterSatClkErrList);
            MainDispatcher.DlgAddLayoutDocument(clkFigureView, Parent.Name + "_钟差图表");
        }
        /// <summary>
        /// XXX功能命令可执行控制
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        bool ClockFigure_CanExecute(object param)
        {
            bool flag = false;
            if (BDSimObject.GlobalStatus == ESimStatus.Inited || BDSimObject.GlobalStatus == ESimStatus.Pause)
            {
                flag = true;
            }
            return flag;
        }
        #endregion

        #region 星历误差配置执行方法
        /// <summary>
        /// 星历误差配置功能命令执行方法
        /// </summary>
        /// <param name="param"></param>
        void mcdEphemerisErrorConfig_Execute(object param)
        {
            EphemerisErrorConfigWnd errorConfigWnd = new EphemerisErrorConfigWnd();  //星历误差配置界面窗口
            errorConfigWnd.DataContext = Parent.CNavMsgFit;   //CNavMsgFit中的属性可作为Datatext的绑定对象
            errorConfigWnd.ShowDialog();
        }
        /// <summary>
        /// 星历误差配置功能命令可执行控制
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        bool mcdEphemerisErrorConfig_CanExecute(object param)
        {
            bool flag = false;
            if (BDSimObject.GlobalStatus == ESimStatus.UnInited || BDSimObject.GlobalStatus == ESimStatus.End)
            {
                flag = true;
            }
            return flag;
        }
        #endregion
        #endregion
    }
}
